import java.io.Serializable;
import java.util.HashSet;
import java.util.Vector;

@SuppressWarnings("serial")
public class State implements Serializable {
	private static int numStates=0;
	private int id;
	private Vector<Transition> transitions;
	public boolean visited;
	public int vertexNo;
	public  State()
	{
		vertexNo = -1;
		visited = false;
		numStates++;
		setId(numStates);
		transitions = new Vector<Transition>();
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public Vector<Transition> getTransitions() {
		return transitions;
	}
	public void setTransitions(Vector<Transition> transitions) {
		this.transitions = transitions;
	}
	public void addTransition(Transition trans)
	{
		this.transitions.add(trans);
	}
	public boolean allTransitionsE()
	{
		for(int i =0; i< transitions.size();i++)
		{
			if(!transitions.get(i).getValue().equals(Transition.EPSILON.toString()))
				return false;
		}
		return true;
	}
	public static int getNumStates()
	{
		return numStates;
	}
	public static void incNumStates()
	{
		numStates++;
	}
	public boolean equals(Object s)
	{
		if(this.id == ((State) s).getId())
			return true;
		else return false;
	}
	public Vector<State> statesReachable(Vector<State> set)
	{
		set.add(this);
		for(int i = 0; i<this.getTransitions().size();i++)
		{
			if(this.getTransitions().get(i).getValue().equals(Transition.EPSILON.toString())){
				State tmp = this.getTransitions().get(i).getDestinationState();
				if(!set.contains(tmp)){
					set = tmp.statesReachable( set);
				}
			}
		}

		return set;


	}
	public void reArrangeIds(int numStates) {
		if(this.getId()>=numStates)
			return;
		else
		{
			this.setId(State.getNumStates());
			State.incNumStates();
			
			for(int i =0; i<this.getTransitions().size();i++)
			{
				this.transitions.get(i).getDestinationState().reArrangeIds(numStates);
			}
		}
		
	}
}
